//
//  TimeCountView.swift
//  koolcar
//
//  Created by xiantian on 2023/11/3.
//

import UIKit

class TimeCountView: UIView {
    
    private var hourBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_backgroundImage(image: UIImage.init(named: "icon_time_red"))
        tempBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCMedium, size: 12)
        tempBtn.setup_titleColor(color: .white)
        return tempBtn
    }()
    
    private var minuteBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_backgroundImage(image: UIImage.init(named: "icon_time_red"))
        tempBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCMedium, size: 12)
        tempBtn.setup_titleColor(color: .white)
        return tempBtn
    }()
    
    private var secondBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_backgroundImage(image: UIImage.init(named: "icon_time_red"))
        tempBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCMedium, size: 12)
        tempBtn.setup_titleColor(color: .white)
        return tempBtn
    }()
    
    ///点1
    private var dot1: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.redColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 12)
        tempLab.text = ":"
        tempLab.textAlignment = .center
        return tempLab
    }()
    
    ///点2
    private var dot2: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.redColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 12)
        tempLab.text = ":"
        tempLab.textAlignment = .center
        return tempLab
    }()
    
    public var hours: String = "" {
        didSet {
            self.hourBtn.setup_titleLabel(text: hours)
        }
    }
    public var minute: String = "" {
        didSet {
            self.minuteBtn.setup_titleLabel(text: minute)
        }
    }
    
    public var second: String = "" {
        didSet {
            self.secondBtn.setup_titleLabel(text: second)
        }
    }    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(hourBtn)
        self.addSubview(minuteBtn)
        self.addSubview(secondBtn)
        self.addSubview(dot1)
        self.addSubview(dot2)
        
        hourBtn.setup_titleLabel(text: "00")
        minuteBtn.setup_titleLabel(text: "00")
        secondBtn.setup_titleLabel(text: "00")
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        
        hourBtn.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
        dot1.snp.makeConstraints { make in
            make.left.equalTo(hourBtn.snp.right)
            make.top.equalTo(0)
            make.width.equalTo(8)
            make.bottom.equalTo(0)
        }
        
        minuteBtn.snp.makeConstraints { make in
            make.left.equalTo(dot1.snp.right)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
            make.width.equalTo(hourBtn.snp.width)
        }
        
        dot2.snp.makeConstraints { make in
            make.left.equalTo(minuteBtn.snp.right)
            make.top.equalTo(0)
            make.width.equalTo(8)
            make.bottom.equalTo(0)
        }
        
        secondBtn.snp.makeConstraints { make in
            make.left.equalTo(dot2.snp.right)
            make.top.equalTo(0)
            make.right.equalTo(0)
            make.width.equalTo(hourBtn.snp.width)
            make.bottom.equalTo(0)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
